<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>数组对象的两个属性的值，转为对象</title>
    <!-- <script src="https://cdn.bootcdn.net/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script> -->
    <script src="lodash.min.js"></script>
    <script src="../helpers/bing.js"></script>
  </head>
  <body>
    <script>
      const lodahs = [
        {
          id: 8278,
          history_result_id: 7,
          time: "2022-01-01",
          number: "22",
          group_name: "EIGHT_RANGE_00000083_GROUPS",
          group_type: "eight",
          sub_index: 5,
        },
        {
          id: 8279,
          history_result_id: 7,
          time: "2022-01-01",
          number: "22",
          group_name: "EIGHT_RANGE_00000084_GROUPS",
          group_type: "eight",
          sub_index: 3,
        },
      ];

      // 使用 lodash 的 keyBy 将 group_name 作为 key, sub_index 作为 value
    //   const result = _.mapValues(_.keyBy(lodahs, "group_name"), "sub_index");

    //   console.log(result);


    const result = lodahs.reduce((acc, { group_name, sub_index }) => {
    acc[group_name] = sub_index;
    return acc;
    }, {});

console.log(result);
    </script>
  </body>
</html>
